package abtractTokens;
/**
 * A token that will store an operator.
 * 
 * @author James Marquardt
 * @author Abraham Santini
 */

public class OperatorToken extends GeneralToken{

	public static final char PLUS = '+';
	public static final char MINUS = '-';
	public static final char MULT = '*';
	public static final char DIV = '/';
	public static final char LFPAR = '(';
	public static final char RTPAR = ')';
	public static final char EXP = '^';
	
	/**
	 * Holds the char value for the operator.
	 */
	private char my_operator;
	/**
	 * The order of precedence for the OperatorToken.
	 */
	private int my_precidence;
	
	/**
	 * Public constructor for OperatorToken.
	 * @param the_operator The operator to be tokenized.
	 */
	public OperatorToken(final String the_value) {
		super(the_value);
		char the_operator = the_value.charAt(0);
		if(the_value.length() > 1 || !(the_operator == PLUS || the_operator == MINUS || the_operator
				== MULT || the_operator == DIV || the_operator == LFPAR || the_operator == RTPAR ||
				the_operator == EXP)) {
			System.out.println("Invalid operator");
			
		} else { 
			my_operator = the_operator; 
			if (my_operator == '(' || my_operator == ')') {
				my_precidence = 1;
			} else if (my_operator == '*' || my_operator == '/') {
				my_precidence = 2;
			} else {
				my_precidence = 3;
			}
				
		}
		setType(TokenEnum.OPERATOR);
		
	}
	/**
	 * Returns the operator for the token.
	 * @return my_operator
	 */
	public char getOperator() {
		return my_operator;
	}
	/**
	 * Return the order of precedence for the OperatorToken.
	 * The lower the value the higher the order of precedence.
	 * @return my_precedence
	 */
	public int getPrecidence() {
		return my_precidence;
	}
	
	
}// end OperatorToken
